from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-24 14:02:47.417236
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 24, Sep, 2022
Time: 14:02:53
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.5066
Nobs: 789.000 HQIC: -50.8346
Log likelihood: 10149.1 FPE: 6.82170e-23
AIC: -51.0394 Det(Omega_mle): 6.09066e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300069 0.053775 5.580 0.000
L1.Burgenland 0.108629 0.035822 3.032 0.002
L1.Kärnten -0.106441 0.019055 -5.586 0.000
L1.Niederösterreich 0.208012 0.074899 2.777 0.005
L1.Oberösterreich 0.103128 0.071967 1.433 0.152
L1.Salzburg 0.251930 0.038235 6.589 0.000
L1.Steiermark 0.038490 0.049984 0.770 0.441
L1.Tirol 0.105895 0.040515 2.614 0.009
L1.Vorarlberg -0.059638 0.034859 -1.711 0.087
L1.Wien 0.054228 0.064410 0.842 0.400
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061875 0.111508 0.555 0.579
L1.Burgenland -0.033654 0.074281 -0.453 0.651
L1.Kärnten 0.048118 0.039513 1.218 0.223
L1.Niederösterreich -0.173168 0.155312 -1.115 0.265
L1.Oberösterreich 0.386651 0.149231 2.591 0.010
L1.Salzburg 0.286802 0.079283 3.617 0.000
L1.Steiermark 0.107763 0.103648 1.040 0.298
L1.Tirol 0.312485 0.084012 3.720 0.000
L1.Vorarlberg 0.026317 0.072284 0.364 0.716
L1.Wien -0.016438 0.133561 -0.123 0.902
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191505 0.027607 6.937 0.000
L1.Burgenland 0.089595 0.018391 4.872 0.000
L1.Kärnten -0.008320 0.009783 -0.850 0.395
L1.Niederösterreich 0.262987 0.038452 6.839 0.000
L1.Oberösterreich 0.127910 0.036947 3.462 0.001
L1.Salzburg 0.047219 0.019629 2.406 0.016
L1.Steiermark 0.018260 0.025661 0.712 0.477
L1.Tirol 0.093499 0.020800 4.495 0.000
L1.Vorarlberg 0.059012 0.017896 3.297 0.001
L1.Wien 0.119316 0.033067 3.608 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108416 0.028277 3.834 0.000
L1.Burgenland 0.044410 0.018837 2.358 0.018
L1.Kärnten -0.015831 0.010020 -1.580 0.114
L1.Niederösterreich 0.192481 0.039386 4.887 0.000
L1.Oberösterreich 0.294711 0.037844 7.788 0.000
L1.Salzburg 0.114439 0.020106 5.692 0.000
L1.Steiermark 0.101641 0.026284 3.867 0.000
L1.Tirol 0.115163 0.021305 5.406 0.000
L1.Vorarlberg 0.071418 0.018331 3.896 0.000
L1.Wien -0.027118 0.033870 -0.801 0.423
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130922 0.051210 2.557 0.011
L1.Burgenland -0.052155 0.034114 -1.529 0.126
L1.Kärnten -0.040223 0.018147 -2.217 0.027
L1.Niederösterreich 0.170546 0.071327 2.391 0.017
L1.Oberösterreich 0.139838 0.068534 2.040 0.041
L1.Salzburg 0.286141 0.036411 7.859 0.000
L1.Steiermark 0.036006 0.047600 0.756 0.449
L1.Tirol 0.163197 0.038582 4.230 0.000
L1.Vorarlberg 0.102985 0.033196 3.102 0.002
L1.Wien 0.064948 0.061338 1.059 0.290
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058902 0.040661 1.449 0.147
L1.Burgenland 0.038236 0.027086 1.412 0.158
L1.Kärnten 0.051083 0.014408 3.545 0.000
L1.Niederösterreich 0.222731 0.056633 3.933 0.000
L1.Oberösterreich 0.284070 0.054416 5.220 0.000
L1.Salzburg 0.049352 0.028910 1.707 0.088
L1.Steiermark -0.004564 0.037794 -0.121 0.904
L1.Tirol 0.148306 0.030634 4.841 0.000
L1.Vorarlberg 0.072816 0.026358 2.763 0.006
L1.Wien 0.080050 0.048702 1.644 0.100
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181108 0.048607 3.726 0.000
L1.Burgenland -0.006205 0.032380 -0.192 0.848
L1.Kärnten -0.061084 0.017224 -3.546 0.000
L1.Niederösterreich -0.082983 0.067701 -1.226 0.220
L1.Oberösterreich 0.193199 0.065051 2.970 0.003
L1.Salzburg 0.056592 0.034560 1.638 0.102
L1.Steiermark 0.232304 0.045181 5.142 0.000
L1.Tirol 0.493364 0.036621 13.472 0.000
L1.Vorarlberg 0.048295 0.031509 1.533 0.125
L1.Wien -0.052334 0.058220 -0.899 0.369
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163215 0.055849 2.922 0.003
L1.Burgenland -0.011178 0.037204 -0.300 0.764
L1.Kärnten 0.066422 0.019790 3.356 0.001
L1.Niederösterreich 0.199075 0.077788 2.559 0.010
L1.Oberösterreich -0.060915 0.074742 -0.815 0.415
L1.Salzburg 0.213978 0.039709 5.389 0.000
L1.Steiermark 0.116034 0.051912 2.235 0.025
L1.Tirol 0.075041 0.042077 1.783 0.075
L1.Vorarlberg 0.124180 0.036203 3.430 0.001
L1.Wien 0.116232 0.066894 1.738 0.082
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.359380 0.032326 11.117 0.000
L1.Burgenland 0.006111 0.021534 0.284 0.777
L1.Kärnten -0.023199 0.011455 -2.025 0.043
L1.Niederösterreich 0.219791 0.045025 4.882 0.000
L1.Oberösterreich 0.179583 0.043262 4.151 0.000
L1.Salzburg 0.045716 0.022984 1.989 0.047
L1.Steiermark -0.016530 0.030048 -0.550 0.582
L1.Tirol 0.106639 0.024355 4.379 0.000
L1.Vorarlberg 0.073102 0.020955 3.489 0.000
L1.Wien 0.050490 0.038719 1.304 0.192
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041140 0.150848 0.191021 0.155699 0.125372 0.112396 0.065474 0.223064
Kärnten 0.041140 1.000000 -0.002980 0.129168 0.041486 0.095457 0.430421 -0.053720 0.101384
Niederösterreich 0.150848 -0.002980 1.000000 0.336288 0.151664 0.300291 0.107679 0.182986 0.323992
Oberösterreich 0.191021 0.129168 0.336288 1.000000 0.231276 0.332092 0.171771 0.171201 0.262723
Salzburg 0.155699 0.041486 0.151664 0.231276 1.000000 0.146582 0.123375 0.148682 0.132407
Steiermark 0.125372 0.095457 0.300291 0.332092 0.146582 1.000000 0.152936 0.139919 0.079168
Tirol 0.112396 0.430421 0.107679 0.171771 0.123375 0.152936 1.000000 0.114003 0.152142
Vorarlberg 0.065474 -0.053720 0.182986 0.171201 0.148682 0.139919 0.114003 1.000000 0.004439
Wien 0.223064 0.101384 0.323992 0.262723 0.132407 0.079168 0.152142 0.004439 1.000000